package com.vincce.sport.core.weixin;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.vincce.sport.controller.TimerTaskController;

@Component
public class WeixinTask extends TimerTaskController{

	/*
	 * 获取关注人数API
	 */
	public static String GET_ATTENTION_TOTAL = "/cgi-bin/user/get?access_token=%s&next_openid=%s";
	
	/*
	 * 获取关注人数API
	 */
	public static String GET_ACCESS_TOKEN = "/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
	/*
	 * 微信API
	 */
	public static final String URL_PREFIX = "https://api.weixin.qq.com";
	
	public static String APP_ID = "wxbd88f264131681f4";

	public static String APP_SECRET = "abf467ae67914fc313d8d9b1380198fc";
	
	//access_token   有效时间7200秒
	public static String TOKEN = "";
	
	public static String TOTAL_ATTENTION = "0";
	/*static{
		GET_ACCESS_TOKEN = String.format(GET_ACCESS_TOKEN, APP_ID,APP_SECRET);
		//获取ACCESS_TOKEN
		Request access_token_request = Request.Get(URL_PREFIX+GET_ACCESS_TOKEN);
		try {
			String response = HttpUtil.fetch(access_token_request);
			String json = new String(response.getBytes("iso-8859-1"), "utf-8");
			System.out.println(json);
			JSONObject object = JSONObject.parseObject(json);
			Map<String, Object> map = JsonUtil.jsonToMap(object);
			if(map.containsKey("access_token")){
				TOKEN = map.get("access_token") == null ? "" : map.get("access_token").toString();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}*/

	@Scheduled(cron="0 1 * * * ?")
	public void getAttention(){		
		weixinTask();
	}
}
